package server;

import java.io.ObjectOutputStream;
import java.net.Socket;

public class SenderConnection implements Runnable{
	private ObjectOutputStream out;
	private Socket socket;
	private Thread thread;
	private Object outPut;
	
	public SenderConnection(Socket socket){
		this.socket = socket;
		outPut = null;
		thread = new Thread(this);
		thread.start();
	}
	
	public void sendObject(Object o){
		outPut = o;
	}
	
	public void run(){
		try{
			out = new ObjectOutputStream(socket.getOutputStream());
			while(true){
				
				if(outPut != null){
					out.writeObject(outPut);
					outPut = null;
				}
			}
		}
		catch(Exception e){
			System.out.println("Problem in -SenderConnection_");
			e.printStackTrace();
		}
	}
}
